#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    void traverse(TreeNode* root, int& count, vector<int>& vi)
    {
        if (root == nullptr)
            return;

        vector<int>::iterator it = vi.begin();
        while (it != vi.end())
        {
            if (root->val == *it)
                break;
            it++;
        }
        if (it == vi.end())
        {
            vi.push_back(root->val);
            count++;
        }
        traverse(root->left, count, vi);
        traverse(root->right, count, vi);
    }
    int numColor(TreeNode* root) {
        int count = 0;
        vector<int> vi;
        traverse(root, count, vi);
        return count;
    }
};